var e = require("../../../../common/vendor.js"), i = require("../../../uv-ui-tools/libs/function/test.js"), t = require("../../../uv-ui-tools/libs/mixin/mpMixin.js"), n = require("../../../uv-ui-tools/libs/mixin/mixin.js"), s = require("./utils.js"), o = require("./mixin.js"), a = require("./props.js");

require("../../../uv-ui-tools/libs/function/index.js"), require("../../../uv-ui-tools/libs/function/digit.js"), 
require("../../../uv-ui-tools/libs/util/route.js"), require("../../../uv-ui-tools/libs/function/debounce.js"), 
require("../../../uv-ui-tools/libs/function/throttle.js");

var r = {
    name: "uv-upload",
    emits: [ "error", "beforeRead", "oversize", "afterRead", "delete", "clickPreview" ],
    mixins: [ t.mpMixin, n.mixin, o.mixin_accept, a.props ],
    data: function() {
        return {
            lists: [],
            isInCount: !0
        };
    },
    watch: {
        fileList: {
            deep: !0,
            immediate: !0,
            handler: function() {
                this.formatFileList();
            }
        },
        deletable: function(e) {
            var i = this;
            e || this.lists.map(function(e) {
                e.deletable = i.deletable;
            });
        }
    },
    methods: {
        formatFileList: function() {
            var e = this, t = this.fileList, n = void 0 === t ? [] : t, s = this.maxCount, o = n.map(function(t) {
                return Object.assign(Object.assign({}, t), {
                    isImage: "image" === e.accept || i.image(t.url || t.thumb),
                    isVideo: "video" === e.accept || i.video(t.url || t.thumb),
                    deletable: "boolean" == typeof t.deletable ? t.deletable : e.deletable
                });
            });
            this.lists = o, this.isInCount = o.length < s;
        },
        chooseFile: function() {
            var e = this;
            this.timer && clearTimeout(this.timer), this.timer = setTimeout(function() {
                var t = e.maxCount, n = e.multiple, o = e.lists;
                if (!e.disabled) {
                    var a;
                    try {
                        a = i.array(e.capture) ? e.capture : e.capture.split(",");
                    } catch (e) {
                        e = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(e);
                        a = [];
                    }
                    s.chooseFile(Object.assign({
                        accept: e.accept,
                        multiple: e.multiple,
                        capture: a,
                        compressed: e.compressed,
                        maxDuration: e.maxDuration,
                        sizeType: e.sizeType,
                        camera: e.camera
                    }, {
                        maxCount: t - o.length
                    })).then(function(i) {
                        e.onBeforeRead(n ? i : i[0]);
                    }).catch(function(i) {
                        e.$emit("error", i);
                    });
                }
            }, 100);
        },
        onBeforeRead: function(e) {
            var t = this, n = this.beforeRead, s = this.useBeforeRead, o = !0;
            i.func(n) && (o = n(e, this.getDetail())), s && (o = new Promise(function(i, n) {
                t.$emit("beforeRead", Object.assign(Object.assign({
                    file: e
                }, t.getDetail()), {
                    callback: function(e) {
                        e ? i() : n();
                    }
                }));
            })), o && (i.promise(o) ? o.then(function(i) {
                return t.onAfterRead(i || e);
            }) : this.onAfterRead(e));
        },
        getDetail: function(e) {
            return {
                name: this.name,
                index: null == e ? this.fileList.length : e
            };
        },
        onAfterRead: function(e) {
            var i = this.maxSize, t = this.afterRead;
            (Array.isArray(e) ? e.some(function(e) {
                return e.size > i;
            }) : e.size > i) ? this.$emit("oversize", Object.assign({
                file: e
            }, this.getDetail())) : ("function" == typeof t && t(e, this.getDetail()), this.$emit("afterRead", Object.assign({
                file: e
            }, this.getDetail())));
        },
        deleteItem: function(e) {
            this.$emit("delete", Object.assign(Object.assign({}, this.getDetail(e)), {
                file: this.fileList[e]
            }));
        },
        onPreviewImage: function(t, n) {
            var s = this, o = this.$uv.deepClone(this.lists);
            o.map(function(e, i) {
                i == n && (e.current = !0);
            });
            var a = o.filter(function(e) {
                return e.isImage;
            }).findIndex(function(e) {
                return e.current;
            });
            this.onClickPreview(t, n), t.isImage && this.previewFullImage && e.index.previewImage({
                urls: this.lists.filter(function(e) {
                    return "image" === s.accept || i.image(e.url || e.thumb);
                }).map(function(e) {
                    return e.url || e.thumb;
                }),
                current: a,
                fail: function() {
                    this.$uv.toast("预览图片失败");
                }
            });
        },
        onPreviewVideo: function(e, i) {
            this.onClickPreview(e, i), this.previewFullVideo && e.isVideo && this.$refs.previewVideo.open(e.url);
        },
        onClickPreview: function(e, i) {
            this.$emit("clickPreview", Object.assign(Object.assign({}, e), this.getDetail(i)));
        }
    }
};

Array || (e.resolveComponent("uv-icon") + e.resolveComponent("uv-loading-icon") + e.resolveComponent("uv-preview-video"))(), 
Math || (function() {
    return "../../../uv-icon/components/uv-icon/uv-icon.js";
} + function() {
    return "../../../uv-loading-icon/components/uv-loading-icon/uv-loading-icon.js";
} + function() {
    return "../uv-preview-video/uv-preview-video.js";
})();

var u = e._export_sfc(r, [ [ "render", function(i, t, n, s, o, a) {
    return e.e({
        a: i.previewImage
    }, i.previewImage ? {
        b: e.f(o.lists, function(t, n, s) {
            return e.e({
                a: t.isImage || t.type && "image" === t.type
            }, t.isImage || t.type && "image" === t.type ? {
                b: t.thumb || t.url,
                c: i.imageMode,
                d: e.o(function(e) {
                    return a.onPreviewImage(t, n);
                }, n),
                e: e.s({
                    width: i.$uv.addUnit(i.width),
                    height: i.$uv.addUnit(i.height)
                })
            } : {
                f: "8c9da633-0-" + s,
                g: e.p({
                    color: "#80CBF9",
                    size: "26",
                    name: t.isVideo || t.type && "video" === t.type ? "movie" : "folder"
                }),
                h: e.t(t.isVideo || t.type && "video" === t.type ? "视频" : "文件"),
                i: e.o(function(e) {
                    return a.onPreviewVideo(t, n);
                }, n),
                j: e.s({
                    width: i.$uv.addUnit(i.width),
                    height: i.$uv.addUnit(i.height)
                })
            }, {
                k: "uploading" === t.status || "failed" === t.status
            }, "uploading" === t.status || "failed" === t.status ? e.e({
                l: "failed" === t.status
            }, "failed" === t.status ? {
                m: "8c9da633-1-" + s,
                n: e.p({
                    name: "close-circle",
                    color: "#ffffff",
                    size: "25"
                })
            } : {
                o: "8c9da633-2-" + s,
                p: e.p({
                    size: "22",
                    mode: "circle"
                })
            }, {
                q: t.message
            }, t.message ? {
                r: e.t(t.message)
            } : {}) : {}, {
                s: "uploading" !== t.status && (i.deletable || t.deletable)
            }, "uploading" !== t.status && (i.deletable || t.deletable) ? {
                t: "8c9da633-3-" + s,
                v: e.p({
                    name: "close",
                    color: "#ffffff",
                    size: "10"
                }),
                w: e.o(function(e) {
                    return a.deleteItem(n);
                }, n)
            } : {}, {
                x: "success" === t.status
            }, "success" === t.status ? {
                y: "8c9da633-4-" + s,
                z: e.p({
                    name: "checkmark",
                    color: "#ffffff",
                    size: "12"
                })
            } : {}, {
                A: n
            });
        })
    } : {}, {
        c: o.isInCount
    }, o.isInCount ? e.e({
        d: e.p({
            name: i.uploadIcon,
            size: "26",
            color: i.uploadIconColor
        }),
        e: i.uploadText
    }, i.uploadText ? {
        f: e.t(i.uploadText)
    } : {}, {
        g: i.disabled ? "" : "uv-upload__button--hover",
        h: e.o(function() {
            return a.chooseFile && a.chooseFile.apply(a, arguments);
        }),
        i: e.n(i.disabled && "uv-upload__button--disabled"),
        j: e.s({
            width: i.$uv.addUnit(i.width),
            height: i.$uv.addUnit(i.height)
        }),
        k: e.o(function() {
            return a.chooseFile && a.chooseFile.apply(a, arguments);
        })
    }) : {}, {
        l: e.sr("previewVideo", "8c9da633-6"),
        m: e.s(i.$uv.addStyle(i.customStyle))
    });
} ], [ "__scopeId", "data-v-8c9da633" ] ]);

wx.createComponent(u);